
package com.elong.common.dao;

import java.util.LinkedHashMap;
import java.util.Map;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;



/**
 * @Description: <p>排序对象<p>
 * @author <mailto:guanguo.gao@corp.elong.com>Guanguo.Gao</mailto>
 * @date 2014年9月30日 下午3:36:28
 * @version <b>1.0</b>
 */
public class Sort {

    private Map<String, Order> field = new LinkedHashMap<>();
    
    public Sort(){
    }
    
    //获得排序规则
    public Sort on(String key, Order order){
        field.put(key, order);
        return this;
    }
    
    /** 获取排序后的对象 **/
    public DBObject getSortObject(){
        DBObject dbo = new BasicDBObject();
        for(String k : field.keySet()){
            dbo.put(k, (field.get(k).equals(Order.ASC)) ? 1 : -1);
        }
        return dbo;
    }
}
